<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h2>axios的config模式</h2>
    <button class="get">get请求</button>
    <button class="post">post请求</button>
    <script src="./lib/axios.js"></script>
    <script>
      // 基地址
      axios.defaults.baseURL='http://ajax-api.itheima.net'
      // 1. 测试get请求
      document.querySelector('.get').onclick = function () {
        axios({
          // get请求传递参数-->拼接到url中
          params: {
            spoken: '好无聊呀!',
          },
          // 方法 默认就是get
          // method: 'get',
          // 地址
          url: '/api/robot',
        }).then((res) => {
          console.log('res:', res)
        })
      }

      // 2.测试post请求
      document.querySelector('.post').onclick = function () {
        axios({
          url: '/api/login',
          method: 'post',
          data: {
            username: 'admin',
            password: '123456',
          },
        }).then((res) => {
          console.log('res:', res)
        })
      }
    </script>
  </body>
</html>
